package org.example.handler;

import cn.dev33.satoken.util.SaResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
    // 全局异常拦截 
    @ExceptionHandler
    public SaResult handlerException(Exception e) {
        e.printStackTrace();
//        判断是否是 SaToken 认证异常
        if (e instanceof cn.dev33.satoken.exception.NotLoginException) {
            return SaResult.error("登录异常").setCode(401);
        }
        return SaResult.error(e.getMessage());
    }
}
